<?php
class Application_Model_Tournament extends App_DbTable
{
	
	public function __construct($id = null){
		parent::__construct(new Application_Model_DbTable_Tournament(), $id);
	}
	public function getAll($pagination = false, $currPage = 1, $checkVisible = true){
		$select = $this->_dbTable->select();
		if($checkVisible){
			$select->where('visible = ?', 1);
		}
		
		if($pagination){
	       	$paginator = Zend_Paginator::factory($select);
			$paginator->setItemCountPerPage(10);
	        $paginator->setPageRange(3);
	       	$paginator->setCurrentPageNumber($currPage);         
			return $paginator;
		}
		else{
			return $this->_dbTable->fetchAll($select);
		}		
	}
	public function getEvents($checkStatus = true, $checkVisible = true){
		$select = $this->_dbTable->select();
		if($checkStatus){
			$select->where('status = ?', 'opened');
		}
		if($checkVisible){
			$select->where('visible = ?', 1);
		}
		$events = array();
		$rowset = $this->_row->findDependentRowset('Application_Model_DbTable_Event', 'Tournament', $select);
		foreach ($rowset as $row){
			$events[] = new Application_Model_Event($row->id);
		}
		return $events;
	}
}